function Wizard() {}

Wizard.prototype = {
    wizardFinish: function() {
        Logger.log("wizardFinish");
        var usrInfo = document.getElementById("username");
        var usrPass = document.getElementById("userpass");
        
//         Logger.log("saving  auth info: " + usrInfo.value + "/" + usrPass.value);
        YAHOO.MoodMill.Account.update(usrInfo.value, usrPass.value);
        
        return true;
    },
    populateAuthFields: function (username, idx) {
        Logger.log("Wizard: populating auth fields");
        
        var usrInfo = document.getElementById("username");
        var usrPass = document.getElementById("userpass");
        
        YAHOO.MoodMill.Account.setAccountURI('http://www.moodmill.com');
        var authObj = YAHOO.MoodMill.Account.getAuthInfo(username, idx);
        if (authObj) {
            usrInfo.value = authObj.user;
            usrPass.value = authObj.password;
        } else {
            Logger.log("Unable to get auth info for username: " + username);
        }
    },
    populatePage2: function() {
        var list = document.getElementById('listacc');
        var item = list.currentItem;
        Logger.log("selected item: " + item);
        var idx = list.currentIndex;
        
//         for(prop in item)
//             Logger.log("Stripteasing: " + prop + ": " + item[prop]);
        Logger.log('populatePage2: ' + idx + ' ' + item.label);
        this.populateAuthFields(item.label, idx);
    },
    test: function() {
        Logger.log("Testing account against MoodMill service");
    },
    init: function() {
        Logger.log("Wizard initializing");
        this.clearListAcc();
        YAHOO.MoodMill.Account.setAccountURI('http://www.moodmill.com');
        var authObjs = YAHOO.MoodMill.Account.getAllAuthInfo();
        if (authObjs != null) {
            Logger.log("Yatta~! We got accounts! " + authObjs.length);
            var list = document.getElementById('listacc');
            for(var i=0;i<authObjs.length;i++) {
                Logger.log("Init: append user " +  authObjs[i].user);
                list.appendItem(authObjs[i].user);
            }
        } else {
            // we should advance to pasge #2
            Logger.log("Please advance to page #2");
            goTo("page-2");
        }
        
        return true;
    },
    clearListAcc: function() {
        var list = document.getElementById('listacc');
        while (list.firstChild)
            list.removeChild(list.firstChild);
    }
}

if (typeof YAHOO.MoodMill.Wizard == "undefined")
    YAHOO.MoodMill.Wizard = new Wizard();